﻿Imports System
Imports System.Text
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports FrameworkTeste
Imports Spring.Objects.Factory.Xml
Imports NHibernate

<TestClass()> Public Class KPIDaoTeste
    Inherits TesteTransacionalInjecaoDependenciaSpring

#Region " ConfigLocations "

    Protected Overrides ReadOnly Property ConfigLocations() As String()
        Get
            NamespaceParserRegistry.RegisterParser(GetType(Spring.Data.Config.DatabaseNamespaceParser))
            Return New [String]() {"assembly://Teste.Leilao.Negoc/Teste.Leilao.Negoc/AutoWired.xml"}
        End Get
    End Property

#End Region

    Private testContextInstance As TestContext
    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    ' You can use the following additional attributes as you write your tests:
    '
    ' Use ClassInitialize to run code before running the first test in the class
    ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    ' End Sub
    '
    ' Use ClassCleanup to run code after all tests in a class have run
    ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
    ' End Sub
    '
    ' Use TestInitialize to run code before running each test
    '<TestInitialize()> Public Overloads Sub Initialize()
    '    MyBase.DefaultRollback = False
    '    MyBase.Initialize()
    'End Sub
    '
    ' Use TestCleanup to run code after each test has run
    ' <TestCleanup()> Public Sub MyTestCleanup()
    ' End Sub
    '
#End Region

#Region "Particoes de Equivalencia"

    'EXEMPLO: Public Const PARTICAO_XXX as String = " Select CAMPO_X from TABELA_Y "

#End Region

#Region "Classes Injetadas"

    Private _particaoEquivalencia As ParticaoEquivalencia
    Public Property ParticaoEquivalencia() As ParticaoEquivalencia
        Get
            Throw New NotImplementedException("Nao esqueca de implementar o codigo abaixo")
            '_particaoEquivalencia = New ParticaoEquivalencia("UMA_CONNECTION_NAME")
            Return _particaoEquivalencia
        End Get
        Set(ByVal value As ParticaoEquivalencia)
            _particaoEquivalencia = value
        End Set
    End Property

    Private _sessionFactory As ISessionFactory
    Public Property SessionFactory() As ISessionFactory
        Get
            Return _sessionFactory
        End Get
        Set(ByVal value As ISessionFactory)
            _sessionFactory = value
        End Set
    End Property

#End Region

    <TestMethod()> Public Sub TiposDeEvento_Native_SQL()

        Dim _session As ISession
        'Dim _sqlNativo As String = "Select COUNT(Uf) as Qtd, Uf as UF from Pessoa as PessoasPorEstado  Group By Uf "
        Dim _sqlNativo As String = " Select ROW_NUMBER() Over(ORDER BY COUNT(Uf)) as i , COUNT(Uf) as Qtd, Uf from Pessoa  Group By Uf "
        Dim _retorno As System.Collections.ArrayList
        Dim _sqlQuery As ISQLQuery

        _session = Me.SessionFactory.OpenSession()

        _sqlQuery = _session.CreateSQLQuery(_sqlNativo).AddEntity(GetType(QtdEventosPorTipo))

        _retorno = _sqlQuery.List()

        For Each _pessoa In _retorno
            Destrinchador.DestrinchaClasse(_pessoa)
        Next

        Assert.IsTrue(True)

    End Sub


    <TestMethod()> Public Sub PessoasPorEstado_Native_SQL()

        Dim _session As ISession
        Dim _sqlNativo As String = " Select ROW_NUMBER() Over(ORDER BY COUNT(Uf)) as i , COUNT(Uf) as Qtd, Uf from Pessoa  Group By Uf "
        Dim _retorno As System.Collections.ArrayList
        Dim _sqlQuery As ISQLQuery

        _session = Me.SessionFactory.OpenSession()

        _sqlQuery = _session.CreateSQLQuery(_sqlNativo).AddEntity(GetType(PessoasPorEstado))

        _retorno = _sqlQuery.List()

        For Each _pessoa In _retorno
            Destrinchador.DestrinchaClasse(_pessoa)
        Next

        Assert.IsTrue(True)

    End Sub

    '<TestMethod()> Public Sub Nome_Da_Operacao_Negativo()
    '    Assert.Inconclusive("Exemplo de teste negativo")
    'End Sub

End Class

